package com.yjf.ljr.activity;

import com.yjf.ljr.R;
import com.yjf.ljr.dataclass.ProjectInfoDataClass;
import com.yjf.ljr.dataclass.ProjectInfoDataClass.ProjectDataInfo;
import com.yjf.ljr.parser.RequestBuilder;
import com.yjf.ljr.parser.RequestBuilder.RequestObject;

import android.os.AsyncTask;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.TextView;

public class ProjectInformationActivity extends IjActivity {
	@ID("tvLoanPurpose")
	private TextView mTvLoanPurpose;// 借款用途
	@ID("tvRepayDivisionWay")
	private TextView mTvRepayDivisionWay;// 还款方式
	@ID("tvLoanedAmount")
	private TextView mTvLoanedAmount;// 已投金额
	@ID("tvAvalableAmount")
	private TextView mTvAvalableAmount;// 还需金额
	@ID("tvStatue")
	private TextView mTvStatue;// 借款状态
	@ID("tvInvestAvlDate")
	private TextView mTvInvestAvlDate;// 起投时间
	@ID("tvDeadline")
	private TextView mTvDeadline;// 截止时间
	private String demandId;// 项目id
	@ID("fail_borrowingdetaile")
	// 加载失败显示界面
	private LinearLayout mLlfail_borrowingdetaile;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_project_information);
		initControl();
	}

	private void initControl() {

		setLeftBtnClick();
		setTitleStr("项目信息");
		demandId = getIntent().getStringExtra("demandId");
		showProgressDialog();
		new ProjectInfoTask(demandId).execute();
	}

	class ProjectInfoTask extends AsyncTask<Void, Void, String> {
		private String demandId;// 项目id
		private ProjectInfoDataClass dc = new ProjectInfoDataClass();

		public ProjectInfoTask(String demandId) {
			this.demandId = demandId;

		}

		@Override
		protected String doInBackground(Void... params) {
			// TODO Auto-generated method stub
			RequestObject mObject = new RequestObject();
			mObject.method = "projectInfo";
			mObject.map.put("demandId", demandId);
			return requestDataAndGetErrorMsg(mObject, dc);
		}

		@Override
		protected void onPostExecute(String result) {
			// TODO Auto-generated method stub
			super.onPostExecute(result);
			if (!TextUtils.isEmpty(result)) {// fail
				mLlfail_borrowingdetaile.setVisibility(View.VISIBLE);
				showToast(result);
			} else {// success
				mLlfail_borrowingdetaile.setVisibility(View.GONE);
				ProjectDataInfo data = dc.projectInfo;
				mTvLoanPurpose.setText(data.loanPurpose);// 借款用途
				mTvRepayDivisionWay.setText(data.repayDivisionWay);// 还款方式
				mTvLoanedAmount.setText(data.loanedAmount);// 已投金额
				mTvAvalableAmount.setText(data.avalableAmount);// 还需金额

				// 1:正在投资 2：投资已满
				// 3：未到时间 4：交易完成
				// 5:等待还款 6.已过投资时间
				if ("1".equals(data.status)) {
					mTvStatue.setText("正在投资");// 借款状态
				} else if ("2".equals(data.status)) {
					mTvStatue.setText("投资已满");// 借款状态
				} else if ("3".equals(data.status)) {
					mTvStatue.setText("未到时间");// 借款状态
				} else if ("4".equals(data.status)) {
					mTvStatue.setText("交易完成");// 借款状态
				} else if ("5".equals(data.status)) {
					mTvStatue.setText("等待还款");// 借款状态
				} else if ("6".equals(data.status)) {
					mTvStatue.setText("已过投资时间");// 借款状态
				} else if ("7".equals(data.status)) {
					mTvStatue.setText("项目成立");// 借款状态
				}
				// mTvStatue.setText(data.status);// 借款状态
				mTvInvestAvlDate.setText(data.investAvlDate);// 起投时间
				mTvDeadline.setText(data.deadline);// 截止时间

			}
			dismissProgressDialog();
		}

	}

}
